<!DOCTYPE html>
<html>
  <head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# githubog: http://ogp.me/ns/fb/githubog#">
    <meta charset='utf-8'>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>mrdoob/eventdispatcher.js · GitHub</title>
    <link rel="search" type="application/opensearchdescription+xml" href="/opensearch.xml" title="GitHub" />
    <link rel="fluid-icon" href="https://github.com/fluidicon.png" title="GitHub" />
    <link rel="apple-touch-icon" sizes="57x57" href="/apple-touch-icon-114.png" />
    <link rel="apple-touch-icon" sizes="114x114" href="/apple-touch-icon-114.png" />
    <link rel="apple-touch-icon" sizes="72x72" href="/apple-touch-icon-144.png" />
    <link rel="apple-touch-icon" sizes="144x144" href="/apple-touch-icon-144.png" />
    <link rel="logo" type="image/svg" href="http://github-media-downloads.s3.amazonaws.com/github-logo.svg" />
    <link rel="xhr-socket" href="/_sockets" />


    <meta name="msapplication-TileImage" content="/windows-tile.png" />
    <meta name="msapplication-TileColor" content="#ffffff" />
    <meta name="selected-link" value="repo_source" data-pjax-transient />
    

    
    
    <link rel="icon" type="image/x-icon" href="/favicon.ico" />

    <meta content="authenticity_token" name="csrf-param" />
<meta content="aIQ3SXPnLqBky5xWspwsF4gjD2PLK7QZoVt9O6Bu8GU=" name="csrf-token" />

    <link href="https://a248.e.akamai.net/assets.github.com/assets/github-fdebe8d3f60746fb87c763a59741ff520ae3d8e8.css" media="all" rel="stylesheet" type="text/css" />
    <link href="https://a248.e.akamai.net/assets.github.com/assets/github2-d530e63e2c132c7f0e6ac7228e7e1ab9ef2a8d94.css" media="all" rel="stylesheet" type="text/css" />
    


      <script src="https://a248.e.akamai.net/assets.github.com/assets/frameworks-92d138f450f2960501e28397a2f63b0f100590f0.js" type="text/javascript"></script>
      <script src="https://a248.e.akamai.net/assets.github.com/assets/github-60db6119a6650bd2041b93418be91ba9e98ce248.js" type="text/javascript"></script>
      
      <meta http-equiv="x-pjax-version" content="57b0dd10af60fd73c78027bc93d63296">

        <link data-pjax-transient rel='permalink' href='/mrdoob/eventdispatcher.js/tree/05112c9d4a0443a16d4ebc15010b72421430965a'>
    <meta property="og:title" content="eventdispatcher.js"/>
    <meta property="og:type" content="githubog:gitrepository"/>
    <meta property="og:url" content="https://github.com/mrdoob/eventdispatcher.js"/>
    <meta property="og:image" content="https://secure.gravatar.com/avatar/a00211a1e1aa4fe920302e7b76da0d91?s=420&amp;d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png"/>
    <meta property="og:site_name" content="GitHub"/>
    <meta property="og:description" content="eventdispatcher.js - JavaScript events for custom objects"/>
    <meta property="twitter:card" content="summary"/>
    <meta property="twitter:site" content="@GitHub">
    <meta property="twitter:title" content="mrdoob/eventdispatcher.js"/>

    <meta name="description" content="eventdispatcher.js - JavaScript events for custom objects" />


    
  <link href="https://github.com/mrdoob/eventdispatcher.js/commits/master.atom" rel="alternate" title="Recent Commits to eventdispatcher.js:master" type="application/atom+xml" />

  </head>


  <body class="logged_out   vis-public env-production  ">
    <div id="wrapper">

      

      
      
      

      
      <div class="header header-logged-out">
  <div class="container clearfix">

    <a class="header-logo-wordmark" href="https://github.com/">Github</a>

    <div class="header-actions">
      <a class="button primary" href="https://github.com/signup">Sign up</a>
      <a class="button" href="https://github.com/login?return_to=%2Fmrdoob%2Feventdispatcher.js">Sign in</a>
    </div>

    <div class="command-bar js-command-bar  in-repository">


      <ul class="top-nav">
          <li class="explore"><a href="https://github.com/explore">Explore</a></li>
        <li class="features"><a href="https://github.com/features">Features</a></li>
          <li class="blog"><a href="https://github.com/blog">Blog</a></li>
      </ul>
        <form accept-charset="UTF-8" action="/search" class="command-bar-form" id="top_search_form" method="get">
  <a href="/search/advanced" class="advanced-search-icon tooltipped downwards command-bar-search" id="advanced_search" title="Advanced search"><span class="mini-icon mini-icon-advanced-search "></span></a>

  <input type="text" data-hotkey="/ s" name="q" id="js-command-bar-field" placeholder="Search or type a command" tabindex="1" autocapitalize="off"
    
      data-repo="mrdoob/eventdispatcher.js"
      data-branch="master"
      data-sha="0d399857c9affef6ea8c9f5d9508684c2b387448"
  >

    <input type="hidden" name="nwo" value="mrdoob/eventdispatcher.js" />

    <div class="select-menu js-menu-container js-select-menu search-context-select-menu">
      <span class="minibutton select-menu-button js-menu-target">
        <span class="js-select-button">This repository</span>
      </span>

      <div class="select-menu-modal-holder js-menu-content js-navigation-container">
        <div class="select-menu-modal">

          <div class="select-menu-item js-navigation-item selected">
            <span class="select-menu-item-icon mini-icon mini-icon-confirm"></span>
            <input type="radio" name="search_target" value="repository" checked="checked" />
            <div class="select-menu-item-text js-select-button-text">This repository</div>
          </div> <!-- /.select-menu-item -->

          <div class="select-menu-item js-navigation-item">
            <span class="select-menu-item-icon mini-icon mini-icon-confirm"></span>
            <input type="radio" name="search_target" value="global" />
            <div class="select-menu-item-text js-select-button-text">All repositories</div>
          </div> <!-- /.select-menu-item -->

        </div>
      </div>
    </div>

  <span class="mini-icon help tooltipped downwards" title="Show command bar help">
    <span class="mini-icon mini-icon-help"></span>
  </span>

    <input type="hidden" name="type" value="Code" />

  <input type="hidden" name="ref" value="cmdform">

  <div class="divider-vertical"></div>

</form>
    </div>

  </div>
</div>


      

      


            <div class="site hfeed" itemscope itemtype="http://schema.org/WebPage">
      <div class="hentry">
        
        <div class="pagehead repohead instapaper_ignore readability-menu ">
          <div class="container">
            <div class="title-actions-bar">
              

<ul class="pagehead-actions">



    <li>
      <a href="/login?return_to=%2Fmrdoob%2Feventdispatcher.js"
        class="minibutton js-toggler-target star-button entice tooltipped upwards"
        title="You must be signed in to use this feature" rel="nofollow">
        <span class="mini-icon mini-icon-star"></span>Star
      </a>
      <a class="social-count js-social-count" href="/mrdoob/eventdispatcher.js/stargazers">
        51
      </a>
    </li>
    <li>
      <a href="/login?return_to=%2Fmrdoob%2Feventdispatcher.js"
        class="minibutton js-toggler-target fork-button entice tooltipped upwards"
        title="You must be signed in to fork a repository" rel="nofollow">
        <span class="mini-icon mini-icon-fork"></span>Fork
      </a>
      <a href="/mrdoob/eventdispatcher.js/network" class="social-count">
        10
      </a>
    </li>
</ul>

              <h1 itemscope itemtype="http://data-vocabulary.org/Breadcrumb" class="entry-title public">
                <span class="repo-label"><span>public</span></span>
                <span class="mega-icon mega-icon-public-repo"></span>
                <span class="author vcard">
                  <a href="/mrdoob" class="url fn" itemprop="url" rel="author">
                  <span itemprop="title">mrdoob</span>
                  </a></span> /
                <strong><a href="/mrdoob/eventdispatcher.js" class="js-current-repository">eventdispatcher.js</a></strong>
              </h1>
            </div>

            
  <ul class="tabs">
    <li class="pulse-nav"><a href="/mrdoob/eventdispatcher.js/pulse" class="js-selected-navigation-item " data-selected-links="pulse /mrdoob/eventdispatcher.js/pulse" rel="nofollow"><span class="mini-icon mini-icon-pulse"></span></a></li>
    <li><a href="/mrdoob/eventdispatcher.js" class="js-selected-navigation-item selected" data-selected-links="repo_source repo_downloads repo_commits repo_tags repo_branches /mrdoob/eventdispatcher.js">Code</a></li>
    <li><a href="/mrdoob/eventdispatcher.js/network" class="js-selected-navigation-item " data-selected-links="repo_network /mrdoob/eventdispatcher.js/network">Network</a></li>
    <li><a href="/mrdoob/eventdispatcher.js/pulls" class="js-selected-navigation-item " data-selected-links="repo_pulls /mrdoob/eventdispatcher.js/pulls">Pull Requests <span class='counter'>1</span></a></li>

      <li><a href="/mrdoob/eventdispatcher.js/issues" class="js-selected-navigation-item " data-selected-links="repo_issues /mrdoob/eventdispatcher.js/issues">Issues <span class='counter'>1</span></a></li>



    <li><a href="/mrdoob/eventdispatcher.js/graphs" class="js-selected-navigation-item " data-selected-links="repo_graphs repo_contributors /mrdoob/eventdispatcher.js/graphs">Graphs</a></li>


  </ul>
  
  <div id="repo_details" class="metabox clearfix
       ">
      <div id="repo_details_loader" class="context-loader" style="display:none">Sending Request&hellip;</div>

        <div class="repo-desc-homepage">
          
    <div class="repository-lang-stats">
      <div class="repository-lang-stats-graph">
      <span class="language-color" style="width:100%; background-color:#f15501;" itemprop="keywords">JavaScript</span>
      </div>
      <ol class="list-tip">
        <li>
            <a href="/languages/JavaScript">
              <span class="color-block language-color" style="background-color:#f15501;"></span>
              <span class="lang">JavaScript</span>
              <span class="percent">100%</span>
            </a>
        </li>
      </ol>
    </div>

<div id="repository_description" class="repository-description">
    <p>JavaScript events for custom objects
      <span id="read_more" style="display:none">&mdash; <a href="#readme">Read more</a></span>
    </p>
</div>


<div class="repository-homepage" id="repository_homepage">
  <p></p>
</div>


        </div>

      <div class="edit-repo-desc-homepage" style="display:none">
        <form accept-charset="UTF-8" action="/mrdoob/eventdispatcher.js/settings/update_meta" id="js-update-repo-meta-form" method="post"><div style="margin:0;padding:0;display:inline"><input name="_method" type="hidden" value="put" /><input name="authenticity_token" type="hidden" value="aIQ3SXPnLqBky5xWspwsF4gjD2PLK7QZoVt9O6Bu8GU=" /></div>
          <p class="error" style="display:none">Sorry, but there was a problem saving your changes.</p>
          <input type="text" id="repository-description-field" class="description-field" name="repo_description" value="JavaScript events for custom objects" placeholder="Add a description to this repository">
          <input type="text" id="repository-homepage-field" class="homepage-field" name="repo_homepage" value="" placeholder="Add a website to this repository">

          <div class="edit-repo-actions">
            <button type="submit" class="button save-button">Save changes</button>
            <span class="cancel">
              <a href="#" class="button danger">Cancel</a>
            </span>
          </div>
</form>      </div>

      
<div class="url-box js-url-box">
  <ul class="native-clones">
      <li><a href="/mrdoob/eventdispatcher.js/archive/master.zip" class="button minibutton " icon_class="mini-icon-download" rel="nofollow" title="Download this repository as a zip file"><span class="mini-icon mini-icon-download"></span>ZIP</a>
  </ul>

  <div class="clone-urls js-clone-urls ">
    <span class="http_clone_url clone-url-button js-clone-url-button selected"><a href="https://github.com/mrdoob/eventdispatcher.js.git" class="js-git-protocol-selector" data-permission="Read-Only" data-url="/users/set_protocol?protocol_selector=http&amp;protocol_type=clone">HTTP</a></span>
<span class="public_clone_url clone-url-button js-clone-url-button"><a href="git@github.com:mrdoob/eventdispatcher.js.git" class="js-git-protocol-selector" data-permission="Read-Only" data-url="/users/set_protocol?protocol_selector=ssh&amp;protocol_type=clone">SSH</a></span>
<span class="public_clone_url clone-url-button js-clone-url-button"><a href="git://github.com/mrdoob/eventdispatcher.js.git" class="js-git-protocol-selector" data-permission="Read-Only" data-url="/users/set_protocol?protocol_selector=gitweb&amp;protocol_type=clone">Git Read-Only</a></span>
    <span class="clone-url">
      <input type="text" readonly spellcheck="false" class="url-field js-url-field" value="https://github.com/mrdoob/eventdispatcher.js.git" >
    </span>
    <span class="clone-url-button">
      <span class="js-zeroclipboard url-box-clippy zeroclipboard-button" data-clipboard-text="https://github.com/mrdoob/eventdispatcher.js.git" data-copied-hint="copied!" title="copy to clipboard"><span class="mini-icon mini-icon-clipboard"></span></span>
    </span>
  </div>
  <p class="url-description"><span class="bold js-clone-url-permission">Read-Only</span> access</p>
</div>

        </div>

<div class="tabnav">

  <span class="tabnav-right">
    <ul class="tabnav-tabs">
          <li><a href="/mrdoob/eventdispatcher.js/tags" class="js-selected-navigation-item tabnav-tab" data-selected-links="repo_tags /mrdoob/eventdispatcher.js/tags">Tags <span class="counter blank">0</span></a></li>
    </ul>
  </span>

  <div class="tabnav-widget scope">


    <div class="select-menu js-menu-container js-select-menu js-branch-menu">
      <a class="minibutton select-menu-button js-menu-target" data-hotkey="w" data-ref="master">
        <span class="mini-icon mini-icon-branch"></span>
        <i>branch:</i>
        <span class="js-select-button">master</span>
      </a>

      <div class="select-menu-modal-holder js-menu-content js-navigation-container">

        <div class="select-menu-modal">
          <div class="select-menu-header">
            <span class="select-menu-title">Switch branches/tags</span>
            <span class="mini-icon mini-icon-remove-close js-menu-close"></span>
          </div> <!-- /.select-menu-header -->

          <div class="select-menu-filters">
            <div class="select-menu-text-filter">
              <input type="text" id="commitish-filter-field" class="js-filterable-field js-navigation-enable" placeholder="Filter branches/tags">
            </div>
            <div class="select-menu-tabs">
              <ul>
                <li class="select-menu-tab">
                  <a href="#" data-tab-filter="branches" class="js-select-menu-tab">Branches</a>
                </li>
                <li class="select-menu-tab">
                  <a href="#" data-tab-filter="tags" class="js-select-menu-tab">Tags</a>
                </li>
              </ul>
            </div><!-- /.select-menu-tabs -->
          </div><!-- /.select-menu-filters -->

          <div class="select-menu-list select-menu-tab-bucket js-select-menu-tab-bucket css-truncate" data-tab-filter="branches">

            <div data-filterable-for="commitish-filter-field" data-filterable-type="substring">

                <div class="select-menu-item js-navigation-item selected">
                  <span class="select-menu-item-icon mini-icon mini-icon-confirm"></span>
                  <a href="/mrdoob/eventdispatcher.js/tree/master" class="js-navigation-open select-menu-item-text js-select-button-text css-truncate-target" data-name="master" rel="nofollow" title="master">master</a>
                </div> <!-- /.select-menu-item -->
            </div>

              <div class="select-menu-no-results">Nothing to show</div>
          </div> <!-- /.select-menu-list -->


          <div class="select-menu-list select-menu-tab-bucket js-select-menu-tab-bucket css-truncate" data-tab-filter="tags">
            <div data-filterable-for="commitish-filter-field" data-filterable-type="substring">

            </div>

            <div class="select-menu-no-results">Nothing to show</div>

          </div> <!-- /.select-menu-list -->

        </div> <!-- /.select-menu-modal -->
      </div> <!-- /.select-menu-modal-holder -->
    </div> <!-- /.select-menu -->

  </div> <!-- /.scope -->

  <ul class="tabnav-tabs">
    <li><a href="/mrdoob/eventdispatcher.js" class="selected js-selected-navigation-item tabnav-tab" data-selected-links="repo_source /mrdoob/eventdispatcher.js">Files</a></li>
    <li><a href="/mrdoob/eventdispatcher.js/commits/master" class="js-selected-navigation-item tabnav-tab" data-selected-links="repo_commits /mrdoob/eventdispatcher.js/commits/master">Commits</a></li>
    <li><a href="/mrdoob/eventdispatcher.js/branches" class="js-selected-navigation-item tabnav-tab" data-selected-links="repo_branches /mrdoob/eventdispatcher.js/branches" rel="nofollow">Branches <span class="counter ">1</span></a></li>
  </ul>

</div>

  
  
  


            
          </div>
        </div><!-- /.repohead -->

        <div id="js-repo-pjax-container" class="container context-loader-container" data-pjax-container>
          


<!-- tree commit key: views10/v8/tree:v21:d758ef817392aa1c60e88a94cbc57312 -->

  <div id="slider">
      <div class="frame-meta">
          

          <p class="history-link js-history-link-replace">
              <a href="/mrdoob/eventdispatcher.js/commits/master">
                <span class="mini-icon mini-icon-history tooltipped" title="Browse commits for this branch"></span>
                16 commits
</a>          </p>

        <div class="breadcrumb">
          <span class='bold'><span itemscope="" itemtype="http://data-vocabulary.org/Breadcrumb"><a href="/mrdoob/eventdispatcher.js" class="js-slide-to" data-branch="master" data-direction="back" itemscope="url"><span itemprop="title">eventdispatcher.js</span></a></span></span><span class="separator"> / </span><form action="/login?return_to=%2Fmrdoob%2Feventdispatcher.js" class="js-new-blob-form tooltipped rightwards new-file-link" method="post" title="Sign in to make or propose changes"><span class="js-new-blob-submit mini-icon mini-icon-new-file"></span></form>
        </div>

        <a href="/mrdoob/eventdispatcher.js/find/master"
           class="js-slide-to" data-hotkey="t" style="display:none">Show File Finder</a>

      </div><!-- ./.frame-meta -->

      

  <div class="frames">
    <div class="frame" data-permalink-url="/mrdoob/eventdispatcher.js/tree/05112c9d4a0443a16d4ebc15010b72421430965a" data-title="mrdoob/eventdispatcher.js · GitHub" data-type="tree">

      <div class="bubble tree-browser-wrapper">

      <table class="tree-browser css-truncate" cellpadding="0" cellspacing="0">
        <thead>
            
  <div class="commit commit-tease js-details-container" >
    <p class="commit-title ">
        <a href="/mrdoob/eventdispatcher.js/commit/05112c9d4a0443a16d4ebc15010b72421430965a" class="message">Added .hasEventListener. Closes</a> <a href="https://github.com/mrdoob/eventdispatcher.js/issues/4" class="issue-link" title="added: hasEventListener( type [, listener] );">#4</a><a href="/mrdoob/eventdispatcher.js/commit/05112c9d4a0443a16d4ebc15010b72421430965a" class="message">.</a>
        
    </p>
    <div class="commit-meta">
      <span class="js-zeroclipboard zeroclipboard-link" data-clipboard-text="05112c9d4a0443a16d4ebc15010b72421430965a" data-copied-hint="copied!" title="Copy SHA"><span class="mini-icon mini-icon-clipboard"></span></span>
      <a href="/mrdoob/eventdispatcher.js/commit/05112c9d4a0443a16d4ebc15010b72421430965a" class="sha-block">latest commit <span class="sha">05112c9d4a</span></a>

      <div class="authorship">
        <img class="gravatar" height="20" src="https://secure.gravatar.com/avatar/a00211a1e1aa4fe920302e7b76da0d91?s=140&amp;d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png" width="20" />
        <span class="author-name"><a href="/mrdoob" data-skip-pjax="true" rel="author">mrdoob</a></span>
        authored <time class="js-relative-date updated" datetime="2013-03-29T08:39:40-07:00" title="2013-03-29 08:39:40">March 29, 2013</time>

      </div>
    </div>
  </div>

        </thead>

        

<tbody class="tree-entries js-deferred-content"
    data-url="/mrdoob/eventdispatcher.js/tree-commits/master">


    <tr>
      <td class="icon"><span class="mini-icon mini-icon-directory"></span></td>
      <td class="content"><a href="/mrdoob/eventdispatcher.js/tree/master/examples" class="js-directory-link js-slide-to css-truncate-target" id="bfebe34154a0dfd9fc7b447fc9ed74e9-0d11471d116f952ea8e1cec17ec33ee7510da44b" title="examples">examples</a></td>
      <td class="age"><time class="js-relative-date" datetime="2013-03-29T08:39:06-07:00" title="2013-03-29 08:39:06">March 29, 2013</time></td>

      <td class="message">
          <a href="/mrdoob/eventdispatcher.js/commit/d0b9e38fb7b29a3269580d4e81230de2f3b2526d" class="message">Added example.</a>
          [<a href="/mrdoob" rel="author">mrdoob</a>]

      </td>
    </tr>
    <tr>
      <td class="icon"><span class="mini-icon mini-icon-directory"></span></td>
      <td class="content"><a href="/mrdoob/eventdispatcher.js/tree/master/src" class="js-directory-link js-slide-to css-truncate-target" id="25d902c24283ab8cfbac54dfa101ad31-432b9ab07840bfd0931f6052dd436f5969e83257" title="src">src</a></td>
      <td class="age"><time class="js-relative-date" datetime="2013-03-29T08:39:40-07:00" title="2013-03-29 08:39:40">March 29, 2013</time></td>

      <td class="message">
          <a href="/mrdoob/eventdispatcher.js/commit/05112c9d4a0443a16d4ebc15010b72421430965a" class="message">Added .hasEventListener. Closes</a> <a href="https://github.com/mrdoob/eventdispatcher.js/issues/4" class="issue-link" title="added: hasEventListener( type [, listener] );">#4</a><a href="/mrdoob/eventdispatcher.js/commit/05112c9d4a0443a16d4ebc15010b72421430965a" class="message">.</a>
          [<a href="/mrdoob" rel="author">mrdoob</a>]

      </td>
    </tr>
    <tr>
      <td class="icon"><span class="mini-icon mini-icon-text-file"></span></td>
      <td class="content"><a href="/mrdoob/eventdispatcher.js/blob/master/LICENSE" class="js-directory-link js-slide-to css-truncate-target" id="9879d6db96fd29134fc802214163b95a-8e4a9190b3fdb9e2573f32546cc37ba1060c9fbf" title="LICENSE">LICENSE</a></td>
      <td class="age"><time class="js-relative-date" datetime="2011-10-26T22:26:02-07:00" title="2011-10-26 22:26:02">October 26, 2011</time></td>

      <td class="message">
          <a href="/mrdoob/eventdispatcher.js/commit/33c0535ea5d3ccc05481a81624358c82ae5ba877" class="message">Added description and usage example to README</a>
          [<a href="/mrdoob" rel="author">mrdoob</a>]

      </td>
    </tr>
    <tr>
      <td class="icon"><span class="mini-icon mini-icon-text-file"></span></td>
      <td class="content"><a href="/mrdoob/eventdispatcher.js/blob/master/README.md" class="js-directory-link js-slide-to css-truncate-target" id="04c6e90faac2675aa89e2176d2eec7d8-0a5f507e467fb7236000f544b5be8b4090652ee8" title="README.md">README.md</a></td>
      <td class="age"><time class="js-relative-date" datetime="2013-03-29T08:38:55-07:00" title="2013-03-29 08:38:55">March 29, 2013</time></td>

      <td class="message">
          <a href="/mrdoob/eventdispatcher.js/commit/42d2d9fad5fbb82ed78d80cd065094b3558d4a5a" class="message">Switched to prototype approach.</a>
          [<a href="/mrdoob" rel="author">mrdoob</a>]

      </td>
    </tr>
</tbody>

      </table>
      </div>

        <div id="readme" class="clearfix announce instapaper_body md">
          <span class="name"><span class="mini-icon mini-icon-readme"></span> README.md</span><article class="markdown-body entry-content" itemprop="mainContentOfPage"><h1>
<a name="eventdispatcherjs" class="anchor" href="#eventdispatcherjs"><span class="mini-icon mini-icon-link"></span></a>eventdispatcher.js</h1>

<h4>
<a name="javascript-events-for-custom-objects" class="anchor" href="#javascript-events-for-custom-objects"><span class="mini-icon mini-icon-link"></span></a>JavaScript events for custom objects</h4>

<h3>
<a name="usage" class="anchor" href="#usage"><span class="mini-icon mini-icon-link"></span></a>Usage</h3>

<div class="highlight"><pre><span class="nt">&lt;script </span><span class="na">src=</span><span class="s">"EventDispatcher.js"</span><span class="nt">&gt;&lt;/script&gt;</span>
<span class="nt">&lt;script&gt;</span>

    <span class="c1">// Adding events to custom object</span>

    <span class="kd">var</span> <span class="nx">Car</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>

        <span class="k">this</span><span class="p">.</span><span class="nx">start</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>

            <span class="k">this</span><span class="p">.</span><span class="nx">dispatchEvent</span><span class="p">(</span> <span class="p">{</span> <span class="nx">type</span><span class="o">:</span> <span class="s1">'start'</span><span class="p">,</span> <span class="nx">message</span><span class="o">:</span> <span class="s1">'vroom vroom!'</span> <span class="p">}</span> <span class="p">);</span>

        <span class="p">};</span>

    <span class="p">};</span>

    <span class="nx">Car</span><span class="p">.</span><span class="nx">prototype</span> <span class="o">=</span> <span class="nb">Object</span><span class="p">.</span><span class="nx">create</span><span class="p">(</span> <span class="nx">EventDispatcher</span><span class="p">.</span><span class="nx">prototype</span> <span class="p">);</span>


    <span class="c1">// Using events</span>

    <span class="kd">var</span> <span class="nx">car</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Car</span><span class="p">();</span>

    <span class="nx">car</span><span class="p">.</span><span class="nx">addEventListener</span><span class="p">(</span> <span class="s1">'start'</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span> <span class="nx">event</span> <span class="p">)</span> <span class="p">{</span>

        <span class="nx">alert</span><span class="p">(</span> <span class="nx">event</span><span class="p">.</span><span class="nx">message</span> <span class="p">);</span>

    <span class="p">}</span> <span class="p">);</span>

    <span class="nx">car</span><span class="p">.</span><span class="nx">start</span><span class="p">();</span>

<span class="nt">&lt;/script&gt;</span>
</pre></div></article>
        </div>
    </div>
  </div>
  <br style="clear:both;">


<br style="clear:both;">

<div id="js-frame-loading-template" class="frame frame-loading large-loading-area" style="display:none;">
  <img class="js-frame-loading-spinner" src="https://a248.e.akamai.net/assets.github.com/images/spinners/octocat-spinner-128.gif?1347543527" height="64" width="64">
</div>


  </div>

        </div>
      </div>
      <div class="modal-backdrop"></div>
    </div>

      <div id="footer-push"></div><!-- hack for sticky footer -->
    </div><!-- end of wrapper - hack for sticky footer -->

      <!-- footer -->
      <div id="footer">
  <div class="container clearfix">

      <dl class="footer_nav">
        <dt>GitHub</dt>
        <dd><a href="https://github.com/about">About us</a></dd>
        <dd><a href="https://github.com/blog">Blog</a></dd>
        <dd><a href="https://github.com/contact">Contact &amp; support</a></dd>
        <dd><a href="http://enterprise.github.com/">GitHub Enterprise</a></dd>
        <dd><a href="http://status.github.com/">Site status</a></dd>
      </dl>

      <dl class="footer_nav">
        <dt>Applications</dt>
        <dd><a href="http://mac.github.com/">GitHub for Mac</a></dd>
        <dd><a href="http://windows.github.com/">GitHub for Windows</a></dd>
        <dd><a href="http://eclipse.github.com/">GitHub for Eclipse</a></dd>
        <dd><a href="http://mobile.github.com/">GitHub mobile apps</a></dd>
      </dl>

      <dl class="footer_nav">
        <dt>Services</dt>
        <dd><a href="http://get.gaug.es/">Gauges: Web analytics</a></dd>
        <dd><a href="http://speakerdeck.com">Speaker Deck: Presentations</a></dd>
        <dd><a href="https://gist.github.com">Gist: Code snippets</a></dd>
        <dd><a href="http://jobs.github.com/">Job board</a></dd>
      </dl>

      <dl class="footer_nav">
        <dt>Documentation</dt>
        <dd><a href="http://help.github.com/">GitHub Help</a></dd>
        <dd><a href="http://developer.github.com/">Developer API</a></dd>
        <dd><a href="http://github.github.com/github-flavored-markdown/">GitHub Flavored Markdown</a></dd>
        <dd><a href="http://pages.github.com/">GitHub Pages</a></dd>
      </dl>

      <dl class="footer_nav">
        <dt>More</dt>
        <dd><a href="http://training.github.com/">Training</a></dd>
        <dd><a href="https://github.com/edu">Students &amp; teachers</a></dd>
        <dd><a href="http://shop.github.com">The Shop</a></dd>
        <dd><a href="/plans">Plans &amp; pricing</a></dd>
        <dd><a href="http://octodex.github.com/">The Octodex</a></dd>
      </dl>

      <hr class="footer-divider">


    <p class="right">&copy; 2013 <span title="0.05624s from fe18.rs.github.com">GitHub</span>, Inc. All rights reserved.</p>
    <a class="left" href="https://github.com/">
      <span class="mega-icon mega-icon-invertocat"></span>
    </a>
    <ul id="legal">
        <li><a href="https://github.com/site/terms">Terms of Service</a></li>
        <li><a href="https://github.com/site/privacy">Privacy</a></li>
        <li><a href="https://github.com/security">Security</a></li>
    </ul>

  </div><!-- /.container -->

</div><!-- /.#footer -->


    <div class="fullscreen-overlay js-fullscreen-overlay" id="fullscreen_overlay">
  <div class="fullscreen-container js-fullscreen-container">
    <div class="textarea-wrap">
      <textarea name="fullscreen-contents" id="fullscreen-contents" class="js-fullscreen-contents" placeholder="" data-suggester="fullscreen_suggester"></textarea>
          <div class="suggester-container">
              <div class="suggester fullscreen-suggester js-navigation-container" id="fullscreen_suggester"
                 data-url="/mrdoob/eventdispatcher.js/suggestions/commit">
              </div>
          </div>
    </div>
  </div>
  <div class="fullscreen-sidebar">
    <a href="#" class="exit-fullscreen js-exit-fullscreen tooltipped leftwards" title="Exit Zen Mode">
      <span class="mega-icon mega-icon-normalscreen"></span>
    </a>
    <a href="#" class="theme-switcher js-theme-switcher tooltipped leftwards"
      title="Switch themes">
      <span class="mini-icon mini-icon-brightness"></span>
    </a>
  </div>
</div>



    <div id="ajax-error-message" class="flash flash-error">
      <span class="mini-icon mini-icon-exclamation"></span>
      Something went wrong with that request. Please try again.
      <a href="#" class="mini-icon mini-icon-remove-close ajax-error-dismiss"></a>
    </div>

    
    
    <span id='server_response_time' data-time='0.05664' data-host='fe18'></span>
    
  </body>
</html>

